package com.ruyuan.payment.system.controller.admin;

import com.ruyuan.payment.server.req.AccountChangeReq;
import com.ruyuan.payment.server.req.AccountQueryReq;
import com.ruyuan.payment.server.resp.CommonResp;
import com.ruyuan.payment.server.resp.AccountQueryResp;
import com.ruyuan.payment.server.resp.PageResp;
import com.ruyuan.payment.server.service.AccountService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("/admin/account")
public class AdminAccountController {

    @Resource
    private AccountService accountService;

    @GetMapping("/query-list")
    public CommonResp queryList(@Valid AccountQueryReq req) {
        CommonResp<PageResp<AccountQueryResp>> commonResp = new CommonResp<>();
        PageResp<AccountQueryResp> list = accountService.queryList(req);
        commonResp.setContent(list);
        return commonResp;
    }

    @PostMapping("/change")
    public CommonResp change(@Valid @RequestBody AccountChangeReq req) {
        CommonResp commonResp = new CommonResp<>();
        accountService.doAccount(req.getMemberId(), req.getAmount(), "调账原因：" + req.getDesc());
        return commonResp;
    }
}
